package com.itheima.socket.sendTCP;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        // 注册服务端
        ServerSocket serverSocket = new ServerSocket(8888);

        // 等待数据到来
        Socket socket = serverSocket.accept();

        // 从socket管道中得到一个字节流
        InputStream is = socket.getInputStream();

        // 把初始字节流包装成数据输入流
        DataInputStream dis = new DataInputStream(is);

        while (true) {
            try {
                String rs = dis.readUTF();
                System.out.println(rs);
            } catch (IOException e) {
                System.out.println("已离线");
                dis.close();
                socket.close();
                break;
            }
        }

    }
}
